<?php

declare(strict_types=1);

namespace app\service\dto;

/**
 * 部分认证结果类
 */
class PartialAuthResult extends SuccessResult
{
    private string $accessToken;
    private string $expires;
    private string $action;
    private array $context;

    public function __construct(string $accessToken, string $expires, string $action, string $message = '', array $context = [])
    {
        $defaultMessage = $action === 'need_bind_phone' ? '需要绑定手机号' : '需要完善资料';
        $this->accessToken = $accessToken;
        $this->expires = $expires;
        $this->action = $action;
        $this->context = $context;

        $code = $action === 'need_bind_phone' ? 4001 : 4002;
        $message = trim($message) !== '' ? $message : $defaultMessage;

        parent::__construct([], $message, $code);
    }

    public function getData(): array
    {
        return [
            'accessToken' => $this->accessToken,
            'expires' => $this->expires,
            'partial' => true,
            'incompleteAction' => $this->action,
            'context' => $this->context,
        ];
    }
}
